package com.rdzn.mall.portal.domain;

import com.rdzn.mall.center.entity.UmsMember;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * SpringSecurity需要的用户详情
 * Created by dingzg on 2018/4/26.
 */
public class AdminUserDetails implements UserDetails {
    private UmsMember user;
//    private List<UmsPermission> permissionList;
//    public AdminUserDetails(UmsAdmin umsAdmin, List<UmsPermission> permissionList) {
//        this.umsAdmin = umsAdmin;
//        this.permissionList = permissionList;
//    }
    public AdminUserDetails(UmsMember user){
        this.user = user;
    }

//    @Override
//    public Collection<? extends GrantedAuthority> getAuthorities() {
//        //返回当前用户的权限
//        return permissionList.stream()
//                .filter(permission -> permission.getValue()!=null)
//                .map(permission ->new SimpleGrantedAuthority(permission.getValue()))
//                .collect(Collectors.toList());
//    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<SimpleGrantedAuthority> list = new ArrayList<>();
        list.add(new SimpleGrantedAuthority("user"));
        return list;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
